<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        /* 线性渐变是属于背景图片的渐变,而不是背景颜色的渐变。 */
        /*盒子的background-image属性可以用linear-gradient()形式创建渐变背景。 */
        /* background-image:linear-gradient(to right,blue,red)  渐变方向，开始颜色，结束颜色。*/
        /* 线性渐变的渐变方向也可以写成度数。如45deg   background-image:linear-gradient(45deg,blue,red) */
        /* 线性渐变的渐变颜色也可以有多个值，并且可以用百分数定义它们出现的位置。 background-image:linear-gradient(45deg,blue,red)*/
        /*  */
        div{
            width: 200px;
            height: 200px;
            border: 1px solid #000;
            margin-bottom: 10px;
        }
        div.box1{
            background-image: linear-gradient(to right,red,blue);
        }
        div.box2{
            background-image: linear-gradient(45deg,red,blue);
        }
        div.box3{
            background-image: linear-gradient(to right,red,orange,yellow,green,blue,purple);
        }
        div.box4{
            background-image: linear-gradient(to right,red,green 20%,blue);
        }
        div.box5{
            background-image: linear-gradient(to right,red,green 80%,blue);
        }
    </style>
</head>
<body>
    <div class="box1"></div>
    <div class="box2"></div>
    <div class="box3"></div>
    <div class="box4"></div>
    <div class="box5"></div>
    <div class="box6"></div>
</body>
</html>